package resources;

import org.eclipse.californium.core.coap.CoAP;
import org.eclipse.californium.core.server.resources.CoapExchange;

/**
 * describe:
 *
 * @author helloworldyu
 * @data 2017/12/7
 */
public class TaskResource extends BaseResource{
	public static final String URL = "devices/${deviceId}/task_result";

	public TaskResource() {
		super(URL);
		getAttributes().setTitle("Sensor Task operation");
	}

	@Override
	public void handlePOST(CoapExchange exchange) {
		byte[] requestPayload = exchange.getRequestPayload();
		System.out.println("post 的数据:"+new String(requestPayload));
		exchange.respond(CoAP.ResponseCode.CREATED,"post task ok");
	}

	@Override
	public void handleDELETE(CoapExchange exchange) {
		exchange.respond(CoAP.ResponseCode.DELETED,"delete task ok");
	}

	@Override
	public void handlePUT(CoapExchange exchange) {
		exchange.respond(CoAP.ResponseCode.CHANGED,"put task ok");
	}

	@Override
	public void handleGET(CoapExchange exchange) {
		exchange.respond(CoAP.ResponseCode.CONTENT,"get task ok");
	}
}